<%@ page import="com.ychs.entity.Member" %>
<%@ page import="com.ychs.entity.College" %>
<%@ page import="com.ychs.entity.Major" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String code = request.getParameter("code");
    String sex = request.getParameter("sex");
    String grade = request.getParameter("grade");
    String nativePlace = request.getParameter("nativePlace");
    String phone = request.getParameter("phone");
    String collegeId = request.getParameter("college");
    String majorId = request.getParameter("major");
    String schoolJob = request.getParameter("schoolJob");
    String joinDate = request.getParameter("joinDate");
    String state = request.getParameter("state");
    String labJob = request.getParameter("labJob");
    String remark = request.getParameter("remark");

    Member member = new Member();
    member.setId(Integer.parseInt(id));
    member.setName(name);
    member.setCode(code);
    member.setSex(Integer.parseInt(sex));
    member.setGrade(Integer.parseInt(grade));
    member.setNativePlace(nativePlace);
    member.setPhone(phone);

    College college = new College();
    college.setId(Integer.parseInt(collegeId));
    Major major = new Major();
    major.setId(Integer.parseInt(majorId));

    member.setCollege(college);
    member.setMajor(major);
    member.setSchoolJob(schoolJob);
    member.setJoinDate(joinDate);
    member.setState(state);
    member.setLabJob(labJob);
    member.setRemark(remark);

    pageContext.setAttribute("member",member);
%>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">

            <form id="memberDetailForm" class="layui-form" action="" lay-filter="formFilter">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名<span style="color: red">*</span></label>
                    <div class="layui-input-block ">
                        <input type="text" class="layui-input"
                               id="name" name="name" lay-verify="name"
                               autocomplete="off" placeholder="请输入姓名" readonly>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">学号<span style="color: red">*</span> </label>
                    <div class="layui-input-block">
                        <input type="number" class="layui-input"
                               id="code" name="code" lay-verify="code"
                               placeholder="请输入学号" autocomplete="off" readonly>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">性别<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="0" title="男" lay-filter="男" disabled>
                        <input type="radio" name="sex" value="1" title="女" lay-filter="女" disabled>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">年级<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input"
                               id="grade" name="grade" lay-verify="required"
                               placeholder="请选择入学年份" lay-reqtext="年级为必填项！"
                               autocomplete="off" readonly>
                    </div>
                </div>

                <div class="layui-form-item" id="area-picker">
                    <label class="layui-form-label">籍贯 <span style="color: red">*</span></label>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select id="province" name="province" class="province-selector"  lay-filter="province" disabled>
                            <option value="">请选择省</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select id="city" name="city" class="city-selector"  lay-filter="city" disabled>
                            <option value="">请选择市</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select id="county" name="county" class="county-selector"  lay-filter="county" disabled>
                            <option value="">请选择区</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="number" class="layui-input"
                               id="phone" name="phone" readonly
                               autocomplete="off">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">院系<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select id="college" name="college" lay-filter="college" disabled>
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">专业<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select id="major" name="major" lay-filter="major"disabled>
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">校内职务<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select name="schoolJob" lay-filter="schoolJob"  disabled>
                            <option value="无">无</option>
                            <option value="班干部">班干部</option>
                            <option value="学生会干部">学生会干部</option>
                            <option value="社团干部">社团干部</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">加入日期<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input"
                               id="joinDate" name="joinDate" readonly>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select id="state" name="state" lay-filter="state" disabled>
                            <option value="正常">正常</option>
                            <option value="退出">退出</option>
                            <option value="毕业">毕业</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">担任的实验室职务<span style="color: red">*</span></label>
                    <div class="layui-input-block">
                        <select id="labJob" name="labJob" lay-filter="labJob" disabled>
                            <option value="无">无</option>
                            <option value="组长">组长</option>
                            <option value="项目经理">项目经理</option>
                            <option value="技术总监">技术总监</option>
                            <option value="副秘书长">副秘书长</option>
                            <option value="秘书长">秘书长</option>
                        </select>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
            <textarea placeholder="请输入备注信息" class="layui-textarea"
                      id="remark" name="remark" readonly></textarea>
                    </div>
                </div>

            </form>

        </div>
    </div>
</div>

<script>
    layui.use(['form','layedit','laydate','layarea'], function () {
        var form = layui.form,
            layedit=layui.layedit,
            layer=layui.layer,
            laydate=layui.laydate,
            initYear,
            layarea = layui.layarea,
            $ = layui.$;

        form.render();

        form.val('formFilter',{
            "id":'${member.id}',
            "name":'${member.name}',
            "code":'${member.code}',
            "sex":'${member.sex}',
            "grade":'${member.grade}',
            "phone":'${member.phone}',
            "joinDate":'${member.joinDate}',
            "state":'${member.state}',
            "labJob":'${member.labJob}',
            "schoolJob":'${member.schoolJob}',
            "labJob":'${member.labJob}',
            "remark":'${member.remark}',
        })

        layarea.render({
            elem: '#area-picker',
            data:{
                province:'${(member.nativePlace).split("-")[0]}',
                city:'${(member.nativePlace).split("-")[1]}',
                county:'${(member.nativePlace).split("-")[2]}'
            }
        });

        let url = 'CollegeServlet';
        let params = {method:'search'};
        let successFn = function (res) {
            res = JSON.parse(res);
            let json = res;
            let collegeId='${member.college.id}';
            for (let i=0;i<json.data.length;i++) {

                if(json.data[i].id==collegeId){
                    $('#college').append("<option value='"+json.data[i].id+"' selected>"+json.data[i].name+"</option>");
                }else{
                    $('#college').append("<option value='"+json.data[i].id+"'>"+json.data[i].name+"</option>");
                }
            }

            //页面加载时，把院系的数据查询出来，并赋值给下拉框
            form.render('select');
        }
        $.get(url, params, successFn);


        url = 'MajorServlet';
        params = {method: 'search', collegeSearch: '${member.college.id}'};
        successFn = function (res) {
            res = JSON.parse(res);
            let majors = res.data;
            for (let i = 0; i < majors.length; i++) {
                if(majors[i].id=='${member.major.id}'){
                    $('#major').append("<option value='"+majors[i].id+"' selected>"+majors[i].name+"</option>");
                }else{
                    $('#major').append("<option value='"+majors[i].id+"'>"+majors[i].name+"</option>");
                }
            }
            form.render('select');
        }
        $.get(url, params, successFn);

    });
</script>